package com.hean.view;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Rect;
import android.graphics.drawable.BitmapDrawable;
import android.util.AttributeSet;
import android.view.View;

import com.hean.activity.R;
import com.hean.entity.Orientation;

public class SensorView extends View {
	private Orientation orientation;
	private Bitmap arrow;

	public SensorView(Context context, AttributeSet attrs) {
		super(context, attrs);
	}

	public Orientation getOrientation() {
		return orientation;
	}

	public void setOrientation(Orientation orientation) {
		this.orientation = orientation;
	}

	@Override
	protected void onDraw(Canvas canvas) {
		super.onDraw(canvas);

		arrow = ((BitmapDrawable) getResources().getDrawable(
				R.drawable.arrow)).getBitmap();

		canvas.drawColor(Color.rgb(255, 255, 255));

		Matrix matrix = new Matrix();
		matrix.setRotate(-orientation.yaw, getWidth() / 2, getHeight() / 2);
		canvas.setMatrix(matrix);

		canvas.drawBitmap(arrow, new Rect(0, 0, arrow.getWidth(), arrow
				.getHeight()), new Rect(getWidth() / 4, getHeight() / 4,
				3 * getWidth() / 4, 3 * getHeight() / 4), null);
	}

}
